/*
 * @Descripttion:
 * @version:
 * @Author: hujianli
 * @Date: 2022-07-03 15:40:25
 * @LastEditors: hujianli
 * @LastEditTime: 2022-07-03 15:58:17
 */
package main

import (
	"fmt"
	"log"
	"os"
)

func check(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	// file, err := os.OpenFile("aardvark.txt", os.O_WRONLY, os.FileMode(0600))
	// options := os.O_WRONLY | os.O_APPEND
	options := os.O_WRONLY | os.O_APPEND | os.O_CREATE

	file_mode, err := os.Stat("aardvark.txt")
	check(err)
	fmt.Println(file_mode.Mode())
	file, err := os.OpenFile("aardvark.txt", options, os.FileMode(0600))
	check(err)
	// _, err = file.Write([]byte("amazing!\n"))
	_, err = file.Write([]byte("os.O_WRONLY | os.O_APPEND amazing append!\n"))
	check(err)
	err = file.Close()
	check(err)
}
